var chargingStationData = [];
var equipmentPowerType = [];
var protocolTypeData = [];

$(document).ready(function() {
	showLoading();
	$('title', parent.document).html($('title').text());
	setBaseUrl();
	addTitle("equipmentInfoSave");
	searchEquipmentInfoSave();
});

function getProtocolType(data) {
	var length = data.length;
	protocolTypeData = data;
	for (var i = 0; i < length; i++) {
		$("#equipmentType").append("<option value='" + data[i].equipmentType + "'>" + data[i].equipmentNameCN + "</option>");
	}
}
function getChargingStation(data) {
	var length = data.length;
	chargingStationData = data;
	for (var i = 0; i < length; i++) {
		$("#chargingStationID").append("<option value='" + data[i].chargingStationID + "'>" + data[i].chargingStationName + "</option>");
	}
}
function getEquipmentType(data) {
	var length = data.length;
	equipmentPowerType = data;
	for (var i = 0; i < length; i++) {
		$("#equipmentPowerType").append("<option value='" + data[i].equipmentPowerType + "'>" + data[i].equipmentPowerTypeName + "</option>");
	}
}
function searchEquipmentInfoSave(){
	createComBody("detailOneBody", equipmentInfoTable, undefined, 1);
    createComBody("detailTwoBody", equipmentInfoTable, undefined, 2);
	$('#equipmentID').hide();
	$('#equipmentID').after('<button type="button" class="btn btn-primary btn-sm autoBtn" onclick="autoInput()">自动</button>');
	$('.autoBtn').after('<button type="button" class="btn btn-primary manualBtn" onclick="manualInput()">手动输入</button>');
	$('.autoBtn').hide();
	selectDate("manufactureDate", 0);
	$('.manualBtn').css({padding: "4px 16px"});
	$('.autoBtn').css({padding: "4px"});
	$('#equipmentID').css({float: "left", width: "75%"})
	$("#equipmentID").attr("readonly", false);
	selectDate("manufactureDate");
	$ajaxList('protocolType', getProtocolType);
	$ajaxList('chargingStation', getChargingStation);
	$ajaxList('equipmentType', getEquipmentType);
	setTimeout(hideLoading, 700);
}
function confirm(){
	return checkForm("saveForm", equipmentInfoTable);
}
function manualInput(){
	$('.manualBtn').hide();
	$('#equipmentID').show();
	$('.autoBtn').show();
}
function autoInput(){
	$('.manualBtn').show();
	$('#equipmentID').hide();
	$('.autoBtn').hide();
	$('#equipmentID').val('');
}
function goback() {
	window.parent.skipMenu('chargingEquipment/equipmentInfo', 'drownDown2', '', 'equipmentPage', 'equipmentInfo');
}
function saveEquipmentInfo(data){
     var result = data && data.result;
     if (result == "Success") {
    	 showMessge(messageContent["Insert.Success"], undefined, goback);
     } else if (result == "NotFound"){
    	 showMessge(messageContent["Insert.Failed"]);
     } else if (result == "EquipmentNameExist"){
         showMessge(messageContent["Equipment.EquipmentNameExist"]);
     } else if (result == "EquipmentNoExist"){
	         showMessge(messageContent["Equipment.EquipmentExist"]);
     } else if (result == "IPandPortExist"){
         showMessge(messageContent["Equipment.EquipmentIPExist"]);
     } else {
    	 showMessge(messageContent["Insert.Error"]);
     }
}
function confirm(){
	return checkForm("saveForm", equipmentInfoTable);
}